package com.iwunu.gateway.service.impl;

import java.util.Date;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.iwunu.gateway.entity.GatewayDevice;
import com.iwunu.gateway.repository.GatewayRepository;
import com.iwunu.gateway.service.GatewayService;
import com.iwunu.gateway.vo.GateWayVo;

@Service
public class GatewayServiceImpl implements GatewayService{
    @Autowired
    private GatewayRepository gatewayRepository;
	@Override
	public GatewayDevice getGatewayByUUID(String uuid) {
		GatewayDevice gw = gatewayRepository.selectGatewayByUUID(uuid);
		return gw;
	}
	@Override
	public GatewayDevice getGatewayByMac(String mac) {
		GatewayDevice gw = gatewayRepository.selectGatewayByUUID(mac);
		return gw;
	}
	@Override
	public String save(GateWayVo gwVo,String ownerId) {
		String uuid = UUID.randomUUID().toString();
		GatewayDevice gw = new GatewayDevice();
		gw.setCreateTime(new Date() );
		gw.setIsDel(false);
		gw.setLocation(gwVo.getLocation());
		gw.setMac(gwVo.getMac());
		gw.setStatus(0);
		gw.setOwnerId(ownerId);
		gw.setType(gwVo.getType());
		gw.setName(gwVo.getName());
		gw.setUuid(UUID.randomUUID().toString());
		gatewayRepository.save(gw);
		return uuid; 
	}
	@Override
	public void del(String uuid) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public int  update(String gMac) {
		return gatewayRepository.updateByMac(gMac);
	}


}
